package com.farm.wcp.client.domain;

import java.util.Set;

import org.apache.commons.lang.StringUtils;

/**
 * @author macpl
 *
 */
public class RemoteKnow {
	private String title; // 知识标题 必填
	private String type; // 知识分类 必填,可以是32位的ID,或者是分类路径用“//”符号分隔，如“常见问题//异常恢复”
	private String text; // 知识正文 必填
	private String writetype; // 知识编辑类型 必填：1分类,0创建人
	private String readtype; // 知识阅读类型 必填：1分类,0创建人
	private String syncid; // 同步ID，通过该ID来判断是否重复创建，如果已经存在该ID则进行更新操作 选填，32位字符串
	private String resourceurl; // 知识来源url 选填
	private String domtype; // 知识类型 选填,不填时默认为1(1:文档知识,5:资源知识,6:引用知识)
	private String fileids; // 资源知识的附件id,多个用逗号(,)分隔 当domtype为2时必填
	private String tags; // 标签 选填，多个标签间用英文逗号(,)分隔
	private String groupid; // 知识小组id 选填
	private String imgid; // 预览图id 选填
	private String typefieldjson; // 分类属性 选填，必须为json格式
	private String state;// 知识状态 选填,1:可用,3:归档

	/**
	 * 編輯权限
	 * 
	 * @author macpl
	 *
	 */
	public enum POPTYPE {
		TYPE("1"), CREATOR("0");

		POPTYPE(String val) {
			this.val = val;
		}

		private String val;

		public String getVal() {
			return val;
		}

	}

	/**
	 * 1:文档知识,5:资源知识,6:引用知识
	 * 
	 * @author macpl
	 *
	 */
	public enum DOMTYPE {
		DOC_KNOW("1"), RESOURCE_KNOW("5"), RESOURCE_WEB("6");

		DOMTYPE(String val) {
			this.val = val;
		}

		private String val;

		public String getVal() {
			return val;
		}

	}

	/**
	 * 1:可用3:归档
	 * 
	 * @author macpl
	 *
	 */
	public enum KNOWSTATE {
		ABLE("1"), ARCHIVES("3");

		KNOWSTATE(String val) {
			this.val = val;
		}

		private String val;

		public String getVal() {
			return val;
		}

	}

	/**
	 * 构造知识
	 * 
	 * @param syncid 本地id，根据此id判断是修改或创建(存在服务器中则修改，此id非知识id，而是在创建时绑定到知识的同步id)
	 * @param title  标题
	 * @param type   分类（可以是32位的ID,或者是分类路径用“//”符号分隔，如“常见问题//异常恢复”）
	 * @param text   内容
	 */
	public RemoteKnow(String syncid, String title, String type, String text) {
		this.title = title;
		this.type = type;
		this.text = text;
		this.writetype = POPTYPE.TYPE.getVal();
		this.readtype = "1";
		this.syncid = syncid;
	}

	/**
	 * 构造知识
	 * 
	 * @param title 标题
	 * @param type  分类（可以是32位的ID,或者是分类路径用“//”符号分隔，如“常见问题//异常恢复”）
	 * @param text  内容
	 */
	public RemoteKnow(String title, String type, String text) {
		this.title = title;
		this.type = type;
		this.text = text;
		this.writetype = POPTYPE.TYPE.getVal();
		this.readtype = "1";
	}

//---------------------------------------------------------
	public String getReadtype() {
		return readtype;
	}

	public String getState() {
		return state;
	}

	public RemoteKnow setState(KNOWSTATE knowstate) {
		this.state = knowstate.getVal();
		return this;
	}

	public String getTypefieldjson() {
		return typefieldjson;
	}

	public RemoteKnow setTypefieldjson(String typefieldjson) {
		this.typefieldjson = typefieldjson;
		return this;
	}

	public String getImgid() {
		return imgid;
	}

	public RemoteKnow setImgid(String imgid) {
		this.imgid = imgid;
		return this;
	}

	public String getGroupid() {
		return groupid;
	}

	public RemoteKnow setGroupid(String groupid) {
		this.groupid = groupid;
		return this;
	}

	public String getTags() {
		return tags;
	}

	public RemoteKnow setTags(String tags) {
		this.tags = tags;
		return this;
	}

	public String getFileids() {
		return fileids;
	}

	public RemoteKnow setFileids(Set<String> fileids) {
		String filestrids = null;
		for (String id : fileids) {
			if (StringUtils.isBlank(filestrids)) {
				filestrids = id;
			} else {
				filestrids = filestrids + "," + id;
			}

		}
		this.fileids = filestrids;
		return this;
	}

	public String getDomtype() {
		return domtype;
	}

	public RemoteKnow setDomtype(DOMTYPE domtype) {
		this.domtype = domtype.getVal();
		return this;
	}

	public String getTitle() {
		return title;
	}

	public RemoteKnow setTitle(String title) {
		this.title = title;
		return this;
	}

	public String getType() {
		return type;
	}

	public RemoteKnow setType(String type) {
		this.type = type;
		return this;
	}

	public String getText() {
		return text;
	}

	public RemoteKnow setText(String text) {
		this.text = text;
		return this;
	}

	public String getWritetype() {
		return writetype;
	}

	/**
	 * 編輯权限
	 * 
	 * @param poptype
	 */
	public RemoteKnow setWritetype(POPTYPE poptype) {
		this.writetype = poptype.getVal();
		return this;
	}

	public String getSyncid() {
		return syncid;
	}

	public RemoteKnow setSyncid(String syncid) {
		this.syncid = syncid;
		return this;
	}

	public String getResourceurl() {
		return resourceurl;
	}

	public RemoteKnow setResourceurl(String resourceurl) {
		this.resourceurl = resourceurl;
		return this;
	}
}
